/*
 * Copyright (c) chao
 *
 * SPDX-License-Identifier: 
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-03-27     chao         first version
 */

#ifndef __LCD_H__

#include <stdint.h>

/*
 * @brief lcd color
 */
#define COLOR_RED                                       ((uint16_t)0xF800)
#define COLOR_GREEN                                     ((uint16_t)0x07E0)
#define COLOR_BLUE                                      ((uint16_t)0x001F)
#define COLOR_WHITE                                     ((uint16_t)0xFFFF)
#define COLOR_BLACK                                     ((uint16_t)0x0000)
#define COLOR_BRED                                      ((uint16_t)0XF81F)           
#define COLOR_GRED                                      ((uint16_t)0XFFE0)
#define COLOR_GBLUE                                     ((uint16_t)0X07FF)
#define COLOR_MAGENTA                                   ((uint16_t)0xF81F)
#define COLOR_CYAN                                      ((uint16_t)0x7FFF)
#define COLOR_YELLOW                                    ((uint16_t)0xFFE0)
#define COLOR_BROWN                                     ((uint16_t)0XBC40) //棕色
#define COLOR_BRRED                                     ((uint16_t)0XFC07) //棕红色
#define COLOR_GRAY                                      ((uint16_t)0X8430) //灰色
#define COLOR_DARKBLUE                                  ((uint16_t)0X01CF) //深蓝色
#define COLOR_LIGHTBLUE                                 ((uint16_t)0X7D7C) //浅蓝色  
#define COLOR_GRAYBLUE                                  ((uint16_t)0X5458) //灰蓝色 
#define COLOR_LIGHTGREEN                                ((uint16_t)0X841F) //浅绿色
#define COLOR_LGRAY                                     ((uint16_t)0XC618) //浅灰色(PANNEL),窗体背景色
#define COLOR_LGRAYBLUE                                 ((uint16_t)0XA651) //浅灰蓝色(中间层颜色)
#define COLOR_LBBLUE                                    ((uint16_t)0X2B12) //浅棕蓝色(选择条目的反色)
#define COLOR_BK                                        (RGB24TORGB16(199, 237, 204))//0xC779
#define RGB24TORGB16(R,G,B) ((uint16_t)((((R)>>3)<<11)|(((G)>>2)<<5)|((B)>>3)))

/*
 * @brief lcd pixel
 */
#if 0
#define LCD_X_PIXEL 800
#define LCD_Y_PIXEL 600
#else
#define LCD_X_PIXEL 960
#define LCD_Y_PIXEL 376
#endif
#define LCD_BPP 32

#define _LCD_CONCAT3(x, y, z) x ## y ## z
#define LCD_CONCAT3(x, y, z) _LCD_CONCAT3(x, y, z)
typedef LCD_CONCAT3(uint, LCD_BPP, _t) lcd_color_t;

/*
 * @brief lcd struction
 */
typedef struct _lcd {
    uint8_t  bpp;          /* 像素8/16/24/32 */
    uint16_t x_size;       /* X方向像素点 */
    uint16_t y_size;       /* Y方向像素点 */
    lcd_color_t pen_color;    /* 笔颜色 */
    lcd_color_t bk_color;     /* 背景颜色 */
} lcd_t;

/*
 * @brief external function
 */
void lcd_set_frame_buff(void *fb);
void lcd_init(void);
uint16_t lcd_get_x_size(void);
uint16_t lcd_get_y_size(void);
void lcd_set_bpp(uint8_t bpp);
uint8_t lcd_get_bpp(void);
void lcd_set_pen_color(lcd_color_t color);
lcd_color_t lcd_get_pen_color(void);
void lcd_set_bk_color(lcd_color_t color);
lcd_color_t lcd_get_bk_color(void);
void lcd_write_pixel(uint16_t x, uint16_t y, lcd_color_t color);
lcd_color_t lcd_read_pixel(uint16_t x, uint16_t y);
void lcd_fill(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, lcd_color_t color);
void lcd_draw_rectangle(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, lcd_color_t color, uint16_t pixel);
void lcd_clear(void);

#endif /* __LCD_H__ */


